import allStore from '../stores';

window.reqListUtil = (function(){
	return {
		//转发
		doForward(requestid, userid , resourceids) {
			let _userid = 0;
			let _nodeid = 0;
			let _workflowid = 0;
			let _agentorbyagentid = 0;
			let _agenttype = 0;
            if(userid.indexOf("+")>-1){
				let array = userid.split("+");
                _userid = array[0];
                _nodeid = array[1];
                _workflowid = array[2];
                _agentorbyagentid = array[3];
                _agenttype = array[4];

                if(_agenttype != "2"){
                    _agentorbyagentid = ""; //被代理人
                }
            }else{
                _userid = userid;
			}
			allStore.wfGlobalStore.controllForwardModal({
				showForward: true,
				requestid: requestid,
                nodeid: _nodeid,
                workflowid: _workflowid,
                forwardflag:"1",
                agentorbyagentid: _agentorbyagentid,
                agenttype: _agenttype,
				'f_weaver_belongto_userid':_userid,
				'f_weaver_belongto_usertype':'0'
			});
		},
		//打印
		doPrint(requestid, beluserid, otherpara='') {
			window.doPrintRequest(requestid, beluserid, otherpara);
		},
		//查看表单日志
		seeFormLog(requestid, nodeid) {
			allStore.wfGlobalStore.controlModifyLogParams({requestid, nodeid});
		},
		//待办行按钮，标记已读
		doReadIt(requestid,userid) {
			this.removeMark(requestid);
			window.doReadRequest(requestid,userid);
		},
		//去掉未读/反馈标示
		removeMark(requestid){
			try {
				document.getElementById("wflist_"+requestid+"span").innerHTML = "";
			} catch (e) {}

		},
		doAttention(requestid, userid){
			var e = event || window.event;
		//  return {'x':e.screenX,'y':e.screenY-100}
			//console.log({'x':e.clientX,'y':e.clientY})
			let aim = location.hash.split("/")
			let result = aim[aim.length-1].split("?")[0]
			let aimStores = {
				listMine:"wfListMineStore",
				listDoing:"wfListDoingStore",
				listDone:"wfListDoneStore",
				supervise:"superviseStore",
				attention:"attentionStore",
				queryFlowResult:"wfQueryResultStore"
			}
			// allStore[aimStores[result]].setClickPotion({'x':e.clientX,'y':e.clientY})
			// allStore[aimStores[result]].followTypeSelectShow=true
			// allStore[aimStores[result]].FollowRequestid=requestid
			// window.followTypeSettingStore.getWorkflowAttentionTypeSet(requestid)
		// this.setState({left:e.screenX,top:e.screenY-100})
		allStore.wfFollowTypeSettingStore.followTypeSelectShow=true
		allStore.wfFollowTypeSettingStore.FollowRequestid=requestid
		allStore.wfFollowTypeSettingStore.isSingle = true
		window.followTypeSettingStore.getWorkflowAttentionTypeSet(requestid)
		},

		//督办
		handle(requestid,f_weaver_belongto_userid){
			requestid = requestid + '_' + f_weaver_belongto_userid;
			window.__currentStore.setShowBatchSupervisor(true,requestid);
		},

		//短信督办
		smsHandle(requestid,f_weaver_belongto_userid){
			window.__currentStore.setSmsParams({requestid})
			window.__currentStore.setSmsVisible(true);
		},

		//邮件督办
		emailHandle(requestid,f_weaver_belongto_userid){
			window.__currentStore.getSendEmailInfo({requestid});
		}
		
	}
})();

//打开表单只去掉标志，不发ajax请求，由表单打开内部置为已读并判断是否刷新列表
window.doReadIt = (requestid, otherpara, obj) => {
	reqListUtil.removeMark(requestid);
};

export const getTopIcon = (urlParams) =>{
	return urlParams.offical == "1" ? <i className="icon-coms-official" /> : <i className="icon-coms-workflow" />;
}

export const getTopIconBgColor = (urlParams) =>{
	return urlParams.offical == "1" ? "#F14A2D" : "#0079DE";
}

window._ListenerCtrl = {
	hasPress: false,
	keyDown: function(e){
		if(e.keyCode === 17)
			_ListenerCtrl.hasPress = true;
	},
	keyUp: function(e){
		if(e.keyCode === 17) 
			_ListenerCtrl.hasPress = false;
	},
	bind: function(){
		jQuery(window).bind("keydown", _ListenerCtrl.keyDown).bind("keyup", _ListenerCtrl.keyUp);
	},
	unbind: function(){
		jQuery(window).unbind("keydown", _ListenerCtrl.keyDown).unbind("keyup", _ListenerCtrl.keyUp);
	}
}
window.attentionListUtil = (function(){
	return {
        doAttention(requestid,id,rand){
            var divId = "attentionDiv_"+requestid+"_"+id+"_"+rand;
			var spanId = "attentionSpan_"+requestid+"_"+id+"_"+rand;
            if(jQuery("#"+divId).find("span").length == 0){
            	jQuery("#"+divId).addClass("wf_attention_div_btn_selected");
                jQuery("#"+divId).append("<span id='"+spanId+"' class='wf_attention_span_delbtn' onclick=\"attentionListUtil.doDel("+requestid+","+id+",'"+rand+"')\">X</span>");
			}else{
                jQuery("#"+divId).removeClass("wf_attention_div_btn_selected");
                jQuery("#"+spanId).remove();
			}
        },
		doDel(requestid,id,rand){
			window.followTypeSettingStore.reqid = requestid
			window.followTypeSettingStore.saveAttention({
				src:'del',
				requestids:requestid,
				ids:id,
				rand:rand
			},"single")
		}
	}
})();

